/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package admin;

import java.io.IOException;
import java.sql.Connection;
import java.util.logging.Level;
import java.util.logging.Logger;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import model.DataWrapper;
import model.Inventory;
import model.Warehouse;

/**
 *
 * @author moustafa
 */
public class AddInventory extends HttpServlet {

    // <editor-fold defaultstate="collapsed" desc="HttpServlet methods. Click on the + sign on the left to edit the code.">
    /**
     * Handles the HTTP <code>GET</code> method.
     * @param request servlet request
     * @param response servlet response
     * @throws ServletException if a servlet-specific error occurs
     * @throws IOException if an I/O error occurs
     */
    @Override
    protected void doGet(HttpServletRequest request, HttpServletResponse response)
    throws ServletException{
        DataWrapper wrapper = DataWrapper.getInstance();
        int warehouseID = Integer.parseInt(request.getParameter("warehouse_id"));
        int productID = Integer.parseInt(request.getParameter("product_id"));
        int quantity = Integer.parseInt(request.getParameter("quantity"));
        wrapper.addInventory(new Inventory(wrapper.getWarehouse(warehouseID, wrapper.getConnection()), wrapper.getProduct(productID, wrapper.getConnection()), quantity), wrapper.getConnection());
        request.getSession().setAttribute("added_message", "Inventory Successfully added!");
        try {
            response.sendRedirect("../admin_pages/add_inventory.jsp");
        } catch (IOException ex) {
            Logger.getLogger(AddWarehouse.class.getName()).log(Level.SEVERE, null, ex);
        }
    }

    /**
     * Handles the HTTP <code>POST</code> method.
     * @param request servlet request
     * @param response servlet response
     * @throws ServletException if a servlet-specific error occurs
     * @throws IOException if an I/O error occurs
     */
    @Override
    protected void doPost(HttpServletRequest request, HttpServletResponse response)
    throws ServletException{

    }

}
